package com.example.ocrappspringboot01.controller;

import com.example.ocrappspringboot01.service.OcrService;
import com.example.ocrappspringboot01.unit.Response;
import net.sourceforge.tess4j.TesseractException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@CrossOrigin
@RestController
public class OcrController {
    @Autowired
    OcrService ocrService;

    @ResponseBody
    @PostMapping(value = "/recognize", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Response recognizeImage(MultipartFile file) throws TesseractException, IOException {
        // 调用OcrService中的方法进行文字识别
        String resultText = ocrService.recognizeText(file);
        return new Response(200,"转换成功",resultText);
    }
}
